Part Number Hot Search : 
74HC4094 LM358WN AS5045 2SK1096M ATR0610 MC10H102 AO741012 TA123
Product Description
Full Text Search
 

To Download PM0014 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  september 2013 rev 3 1/46 PM0014 programming manual general-purpose dsp library for st10 introduction stmicroelectronics? st10-dsp microcontroller family offers an attractive set of digital signal processing (dsp) features. the 16-bit multiply-accumulate unit (mac) of the st10-dsp microcontrollers allows all data acquisition (average, max/min), control oriented signal processing (pid, pd) and filtering (fir, iir) widely used in numerous applications. in addition, the combination of st10 real time cpu performances with the mac unit makes st10-dsp microcontrollers superior in a lot of applications like electronic steering, suspension, engine control, airbag, etc. the st10-dsp devices are identified by the number 2 in the first of the three digits of the variant code (e.g.: st10f269). this document provides a st10-dsp library. the st10-dsp library is a set of optimized routines made for c programmers using st10f2xx devices. this library is made of arithmetic and signal processing functions callable from c and fully compatible with the tasking c compiler. it facilitates the evaluat ion and the use of the most common digital filtering routines with the st10-dsp microcontrollers. www.st.com
contents PM0014 2/46 contents 1 st10-dsp features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.1 harvard architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.2 multiply and accumulate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.3 minimum and maximum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.4 instruction repeat unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.5 barrel shifter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.6 real-time aspects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.7 st10 intrinsic benchmarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2 st10-dsp library benchmarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.1 performance considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.2 filter functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 3 using the st10-dsp library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.1 library content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.2 how to install st10-dsp library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.3 calling a function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.4 tool chain compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3.5 st10 device compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3.6 st10 mac configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3.7 interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3.8 naming convention and parameter passing . . . . . . . . . . . . . . . . . . . . . . . . 9 3.8.1 arithmetic functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3.8.2 filter functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3.9 testing a function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3.9.1 test environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3.9.2 using crossview debugger for testing . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3.10 memory reservations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3.10.1 data alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3.10.2 memory reservations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 3.10.3 memory model aspects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
PM0014 contents 3/46 4 developing new functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 4.1 examples of functions for data acquisition . . . . . . . . . . . . . . . . . . . . . . . . 12 4.1.1 detection of the minimum or maximum in a collection of samples . . . . 12 4.1.2 computing the sum of a collection of samples . . . . . . . . . . . . . . . . . . . 12 4.1.3 search for an element within a collection of samples . . . . . . . . . . . . . . 12 4.2 developing your own dsp functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 5 arithmetic library functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 5.1 overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 5.2 addition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 5.2.1 add_16 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 5.2.2 add_32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 5.2.3 cadd_16 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 5.2.4 cadd_32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 5.3 subtraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 5.3.1 sub_16 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 5.3.2 sub_32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 5.3.3 csub_16 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 5.3.4 csub_32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 5.4 multiplication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 5.4.1 mul_q15_q15_q31 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 5.4.2 mul_q31_q31_q31 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 5.4.3 cmul_q15_q15_q15 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 5.4.4 cmul_q31_q31_q31 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 5.5 division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 5.5.1 div_q31_q15_q15 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 5.5.2 div_q63_q31_q31 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 5.5.3 cdiv_q31_q15_q15 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 5.5.4 cdiv_q31 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 5.6 matrix multiply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 5.6.1 mmul_q15_q15_q15 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 5.6.2 mvm_q15_q15_q15 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 5.7 function approximation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 5.7.1 sqrt_p16q16_p8q8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 6 signal processing library func tions . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
contents PM0014 4/46 6.1 overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 6.2 data type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 6.3 finite impulse response filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 6.3.1 fir_q15_q15_q15 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 6.3.2 fir_q15_q31_q15 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 6.3.3 fir_q31_q31_q31 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 6.4 infinite impulse response filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 6.4.1 iir2_q15_q15_q15 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 6.4.2 iirbiquad5_q15_q15_q15 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 7 revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
PM0014 st10-dsp features 5/46 1 st10-dsp features st10 is a combined cpu and dsp. as a cpu, it is a powerful real time oriented 16-bit cpu. as a dsp, it is a single mac 16 by 16-bit multiplier with a 40-bit accumulator. 1.1 harvard architecture st10-dsp has an harvard architecture to allow on every instruction cycle: 1 opcode fetch, 2 operand reads, 1 optional operand write. 1.2 multiply and accumulate st10 supports different multiply and accumulate instructions with different addressing modes. with the comac [rx+], [ry+], in a single instruction cycle, st10 is able to: to fetch 2 operands addressed by rx and ry, to update 2 pointers (increment, decrement, add an index) comacm is similar to comac except that st10 also moves 1 operand to the bottom of the table (useful in data acquisition routines). 1.3 minimum and maximum st10 has 2 instructions for minimum and maximum detection (comin and comax). combined with auto-incrementat ion, those instructions allow st10 to scan a table of samples and detect either the minimum or the maximum in one instruction cycle per sample. 1.4 instruction repeat unit each instruction can be repeated either an immediate number of times or a variable number of times. register mrw is used to repeat a variable number of times. repeat sequences can be interrupted. this allows st10-dsp to compute a fir (16 by 16; real) at a rate of 1 tap per instruction cycle. 1.5 barrel shifter st10-dsp has a barrel shifter connected to the accumulator: any result or value loaded into the accumulator can be shifted. the shift value must be between 0 and 8 (included).
st10-dsp features PM0014 6/46 1.6 real-time aspects the st10-dsp is both a real time cpu and a dsp. any dsp code developed for st10-dsp can be interrupted at any time (including during repeat sequences) and execution resumed after the interrupt routine. during the interrupt, bit mr remains set to indicate that a repeated instruction has been interrupted. latency: there is no added latency on interrupts when dsp functions are used. interrupt routine requirements: the only requirement for interrupt routines that are using the dsp and that are interrupting a dsp function is to save and restore the mac registers at the entry point and exit point of the routine. this control can be automatically done by tasking tool chain by using "#pragma savemac" on each task using dsp functions (for details, refer to tasking user?s manual). 1.7 st10 intrinsic benchmarks table 1. st10 intrinsic benchmarks benchmark execution time (no. of cycles) comments fir 16*16 real n iir real df2 2n proportional integrator differentiator (pid) 6n u(n) = u(n-1)+k0*e( n)+k1*e(n-1)+k2*e(n-2) array search: index of the highest value (signed or unsigned) 1.5n 1n to search for the maximum + 0.5n to retrieve its address. (n: number of elements)
PM0014 st10-dsp library benchmarks 7/46 2 st10-dsp library benchmarks 2.1 performance considerations the performance figures reported underneath have been obtained with all operands mapped into st10 dual port ram (dpram). please note that different memory mapping will lead to longer execution ti me and this could explain differences between the times reported here and the times on other applications. (for details see "st10-dsp programming" application note). 2.2 filter functions the following table illustrates the st10-d sp capabilities in f iltering functions: table 2. st10-dsp capabilities function code size (byte) number of instruction cycles fir 16 *16 real 88 30 + samp *(12 + coef) fir 16* 32 real 130 34 + samp *(16 + 2*coef) fir 32* 32 real 194 34 + samp *(20 + 4*coef) iir direct 2 130 36 + samp *(17 + coef) iir cascaded biquad cells 136 34 + samp *(16 + 15*coef)
using the st10-dsp library PM0014 8/46 3 using the st10-dsp library 3.1 library content the library package consists of 5 main directories: 4 directories for the libraries (binary and include file) for each st10 memory model: tiny, small, medium, large. 1 directory for all test cases: 1 subdirectory per library function. the file structure is the following: figure 1. st10-dsp library directory structure 3.2 how to install st10-dsp library the st10-dsp library is delivered as an archive file with .zip extension (see directory structure description above).to install the st10-dsp library, you need to unzip the file in the directory where you want the library to be copied into. note: please, read the readme.txt file in the ar chive file for specific details on the release. 3.3 calling a function the functions have been writ ten to be called by a c langu age program. calling from assembly language program is possible with respect to parameter passing. library users have to save their different used registers before calling a function. see section 1.6 real-time aspects on page 6 in previous chapter for more details. to include a function in a c language program, it is needed to: include the "libst10.h", link the code with th e object library file "lib_yyyy.lib " of the relevant memory model. model_lib 1 directory per memory model 1 directory per function lib_model-name.lib libst10.h test_case yyy yyy.in yyy.res read me file documentation current directory ai14869
PM0014 using the st10-dsp library 9/46 3.4 tool chain compatibility as st10 has different memory models, a library file has been generated for each memory model: tiny, sma ll, medium, large. st10-dsp library is compatible with tasking tool chain (v7.0r1 and upward). 3.5 st10 device compatibility the st10-dsp library is defined to be compat ible with all st10-dsp variants, including the bond-out. as a consequence, it implements the needed workarounds for the functional features that may be on silicon devices (see resp ective product errata-sheets). 3.6 st10 mac configuration as this library has be done pr imarily for filtering functions, it assumes fractional variables are used . as a consequence, users shall set bit "mp" in the mac control word either at the reset sequence or before calling any function. 3.7 interrupts as explained before, any dsp code developed for st10 can be interrupted at any time and execution resumed after the interrupt routine. there is no added latency when the dsp library is used. interrupt routin e requirements: the only requirements are only when the dsp unit is used by task that have different priorities: the interrupting task that may interrupt another task using the dsp should save and restore the mac registers at the entry point and exit point of the routine. ( use #pragma savemac in tasking tool chain). 3.8 naming convention and parameter passing the name of a function begins with a lowercase. each uppercase starts a new word in the name. underscore is used to separate type of data. types after the name indicate the types of the parameters passed to the function. example: fir_q15_q31_q15 the first q15 indicates the inputs format. q31 corresponds to the type of coefficients. the last q15 indicates the output format. variable formats: q31 means a signed fractional variable with two?s complement fractional format using the 1.31 format (1 signed, 31 fractional bits). q15 means a signed fractional variable with two?s complement fractional format using the 1.31 format (1 signed, 15 fractional bits).
using the st10-dsp library PM0014 10/46 3.8.1 arithmetic functions when applicable, the parameters are passed in the following order: left operator imaginary part msb left operator imaginary part lsb left operator real part msb left operator real part lsb right operator imaginary part msb right operator imaginary part lsb right operator real part msb right operator real part lsb pointer to an output array. 3.8.2 filter functions there is only one parameter to be passed: pointer on a filter structure. this structure is defined in the filter functions chapter. 3.9 testing a function all functions of the dsp library are delivered with their test case. 3.9.1 test environment for each functions, test files have been created in the testmain directory: x.in : file of input data on hexadecimal format. x.res : this file contains outputs obtained by running the asm source. inputs are those of the file x.in. results are on hexadecimal format in x.res. 3.9.2 using crossview debugger for testing crossview debugger has been used for the verification of the results thanks to the provided test vectors. a tasking project can contain the source asm or c function and a main function. the output result can be displayed on a virtual io or a hyperterminal. 3.10 memory reservations 3.10.1 data alignment as the library doesn?t use 8-bit values, there?s no data alignment restraint, even for q1.31 variables.
PM0014 using the st10-dsp library 11/46 3.10.2 memory reservations filtering functions and spectral functions have to allocate data in dp-ram (see section 2.1 performance considerations on page 7). there are several means to do that. the easiest is certainly to declare theses variables as global and to use iram directive: example: iram short delayline[numbercoeffs] ... void main() {...} if you want this variable to be local, you have to declare the variable as a static one and use the iram directive. example: static _iram delayline[numbercoeffs]; 3.10.3 memory model aspects tiny and small models library function?s argument can not be stored as far data (use only near data). medium and large models the arguments of the function must be in the same memory page. in fact, the same data page pointer is used for all the arguments of the function. e.g.: add_16(a,b,&c) a and b are located in the same data page an argument that is a pointer must be an address contained in the same data page than the other arguments. e.g.1: c is located in the same data page than a and b. e.g. 2: firq15_q15_q15(&fir) where: fir.coeffptr is a pointer fir.delaylineptr is a pointer fir.coeffptr and fir.delaylineptr must address data in the same page. as fir.delaylineptr must be located in dpram, it could be a solution to map ram in the same page than dpram (generally page number 3).
developing new functions PM0014 12/46 4 developing new functions this library has been done for filtering. other general purpose functions or application segment specific functions can be developed. 4.1 examples of function s for data acquisition 4.1.1 detection of the minimum or maximum in a collection of samples st10 instructions (comin and comax) allow to detect the maximum or the minimum between the accumulator and an external operand. using a dsp loop with pointer auto- modification, the minimum or the maximum of a parameter in a collection of samples can be detected at a rate of one instruction cycle per sample for 16-bit operands and for 32-bit operands. 4.1.2 computing the sum of a collection of samples using a dsp loop with st10 instruction coadd allows to compute the sum of a collection of samples at a rate of one instruction cycle per sample for both 16-bit and 32-bit operands. 4.1.3 search for an element within a collection of samples using a dsp loop with st10 instruction cocmp allow to compare an external operand with the accumulator at a rate of one instruction cycle per sample for both 16-bit and 32-bit operands. 4.2 developing your own dsp functions please refer to the application note an1442 - signal processing with st10-dsp for more information.
PM0014 arithmetic library functions 13/46 5 arithmetic library functions 5.1 overview in this part, principal arithmetic functions for c programmers on st10 are presented. for each operation, four function types have been created according to parameters: real parameters in single precision, real parameters in double precision, complex parameters in single precision, complex parameters in double precision. code size results will be given in bytes and performance ones in instruction cycles (1 instruction cycle is equal to two st10 cpu clock cycles). 5.2 addition 5.2.1 add_16 add_16 (short op1, short op2, short *output) description: addition of two real 16-bit inputs. argument: op1 op2 output left operand right operand output pointer algorithm: op1 + op2 = output assembly source code: add_16.asm code size and cycles: size: 6 bytes instruction cycles: 10 test: two files are provided to test the function: an input vector file (add_16.in) and an output vector file (add_16.res): add_16.in is made as follows: left operand1, right operand1, left operand2, right operand2, ... add_16.res is made as follows: output operand1, output operand2, ...
arithmetic library functions PM0014 14/46 5.2.2 add_32 add_32 (short leftopmsb, short leftoplsb, short rightopmsb, short rightoplsb, long *output) description: addition of two real 32-bit operands. argument: leftopmsb left operand most significant bits. leftoplsb left operand least significant bits. rightopmsb right operand most significant bits. rightoplsb right operand least significant bits. output output pointer. algorithm: leftop + rightop = output note: set the ms bit field of the mcw register to have a saturated result (signed arithmetic) assembly source code: add_32.asm code size and cycles: size: 20 bytes instruction cycles: 14 test: two files are provided to test the function: an input vector file (add_32.in) and an output vector file (add_32.res): add_32.in is made as follows: leftopmsb1, leftoplsb1, rightopmsb1, rightoplsb1 leftopmsb2, leftoplsb2, rightopmsb2, rightoplsb2 ... add_32.res is made as follows: outputlsb1, outputmsb1, outputlsb2, outputmsb2, ...
PM0014 arithmetic library functions 15/46 5.2.3 cadd_16 cadd_16 (short leftop_i, short leftop_r, short rightop_i, short rightop_r, long *output) description: addition of two complex 16-bit operands. argument: leftop_i left operand imaginary part. leftop_r left operand real part. rightop_i right operand imaginary part. rightop_r right operand real part. output output pointer. algorithm: leftop_r + rightop_r = output_r leftop_i + rightop_i = output_i note: output imaginary part is contained in the highest address (pointed by output + 2). output real part is contained in the lowest address (pointed by output). assembly source code: cadd_16.asm code size and cycles: size: 14 bytes instruction cycles: 18 test: two files are provided to test the function: an input vector file (cadd_16.in) and an output vector file (cadd_16.res): cadd_16.in is made as follows: leftop_i1, leftop_r1, rightop_i1, rightop_r1 leftop_i2, leftop_r2, rightop_i2, rightop_r2 ... cadd_16.res is made as follows: output_i1,output_r1 output_i2,output_r2 ...
arithmetic library functions PM0014 16/46 5.2.4 cadd_32 cadd_32 (short leftopmsb_i, short leftoplsb_i, short leftopmsb_r, short leftoplsb_r, short rightopmsb_i, short rightoplsb_i, short rightopmsb_r, short rightopmsb_i, long *output) description: addition of two complex 32-bit operands. argument: leftopmsb_i left operand imaginary part most significant bits. leftoplsb_i left operand imaginary part least significant bits. leftopmsb_r left operand real part most significant bits. leftoplsb_r left operand real part least significant bits. rightopmsb_i right operand imaginary part most significant bits. rightoplsb_i right operand imaginary part least significant bits. rightopmsb_r right operand real part most significant bits. rightoplsb_r right operand real part least significant bits. output output pointer algorithm: leftop_r + rightop_r = output_r leftop_i + rightop_i = output_i note: output imaginary part is contained in the highest addresses (pointed by output + 4). output real part is contained in the lowest addresses (pointed by output). set the ms bit-field of the mcw register to have a saturated result (signed arithmetic). assembly source code: cadd_32.asm code size and cycles: size: 52 bytes instruction cycles: 25 test: two files are provided to test the function: an input vector file (cadd_32.in) and an output vector file (cadd_32.res): cadd_32.in is made as follows: leftopmsb_i1, leftoplsb_i1, leftopmsb_r1, leftoplsb_r1, rightopmsb_i1, rightoplsb_i1, rightopmsb_r1, rightoplsb_r1, leftopmsb_i2, leftoplsb_i2, leftopmsb_r2, leftoplsb_r2, rightopmsb_i2, rightoplsb_i2, rightopmsb_r2, rightoplsb_r2, ... cadd_32.res is made as follows: outputlsb_r1, outputmsb_r1, outputlsb_i1, outputmsb_i1 outputlsb_r2, outputmsb_r2, outputlsb_i2, outputmsb_i2, ...
PM0014 arithmetic library functions 17/46 5.3 subtraction 5.3.1 sub_16 sub_16 (short op1, short op2, short *output) description: subtraction of two real 16-bit inputs. argument: op1 left operand. op2 right operand. output output pointer. algorithm: op1 - op2 = output note: assembly source code: sub_16.asm code size and cycles: size: 6 bytes instruction cycles: 10 test: two files are provided to test the function: an input vector file (sub_16.in) and an output vector file (sub_16.res): sub_16.in is made as follows: left operand1, right operand1, ... sub_16.res is made as follows: output operand1, ...
arithmetic library functions PM0014 18/46 5.3.2 sub_32 sub_32 (short leftopmsb, short leftoplsb, short rightopmsb, short rightoplsb, long *output) description: subtraction of two real 32-bit inputs. argument: leftopmsb left operand most significant bits. leftoplsb left operand least significant bits. rightopmsb right operand most significant bits. rightoplsb right operand least significant bits. output output pointer. algorithm: leftop - rightop = output note: set the ms bit-field of the mcw register to have a saturated result (signed arithmetic). assembly source code: sub_32.asm code size and cycles: size: 20 bytes instruction cycles: 14 test: two files are provided to test the function: an input vector file (sub_32.in) and an output vector file (sub_32.res): sub_32.in is made as follows: leftopmsb1, leftoplsb1, rightopmsb1, rightoplsb1 ... sub_32.res is made as follows: outputmsb1, outputlsb1,...
PM0014 arithmetic library functions 19/46 5.3.3 csub_16 csub_16 (short leftop_i, short leftop_r, short rightop_i, short rightop_r, long *output) description: subtraction of two complex 16-bit operands. argument: leftop_i left operand imaginary part. leftop_r left operand real part. rightop_i right operand imaginary part. rightop_r right operand real part. output output pointer. algorithm: leftop_r - rightop_r = output_r leftop_i - rightop_i = output_i note: output imaginary part is contained in the highest address (pointed by output + 2). output real part is contained in the lowest address (pointed by output). assembly source code: csub_16.asm code size and cycles: size: 14 bytes instruction cycles: 18 test: two files are provided to test the function: an input vector file (csub_16.in) and an output vector file (csub_16.res): csub_16.in is made as follows: leftop_i1, leftop_r1, rightop_i1, rightop_r1 leftop_i2, leftop_r2, rightop_i2, rightop_r2 ... csub_16.res is made as follows: output_r1,output_i1 ...
arithmetic library functions PM0014 20/46 5.3.4 csub_32 csub_32 (short leftopmsb_i, short leftoplsb_i, short leftopmsb_r, short leftoplsb_r, short rightopmsb_i, short rightoplsb_i, short rightopmsb_r, short rightopmsb_i, long *output) description: subtraction of two complex 32-bit operands. argument: leftopmsb_i left operand imaginary part most significant bits. leftoplsb_i left operand imaginary part least significant bits. leftopmsb_r left operand real part most significant bits. leftoplsb_r left operand real part least significant bits. rightopmsb_i right operand imaginary part most significant bits. rightoplsb_i right operand imaginary part least significant bits. rightopmsb_r right operand real part most significant bits. rightoplsb_r right operand real part least significant bits. output output pointer. algorithm: leftop_r - rightop_r = output_r leftop_i - rightop_i = output_i note: output imaginary part is contained in the highest addresses (pointed by output + 4). output real part is contained in the lowest addresses (pointed by output). set the ms bit-field of the mcw register to have a saturated result (signed arithmetic). assembly source code: csub_32.asm code size and cycles: size: 52 bytes instruction cycles: 25 test: two files are provided to test the function: an input vector file (csub_32.in) and an output vector file (csub_32.res): csub_32.in is made as follows: leftopmsb_i1, leftoplsb_i1, leftopmsb_r1, leftoplsb_r1, rightopmsb_i1, rightoplsb_i1, rightopmsb_r1, rightoplsb_r1, ... csub_32.res is made as follows: outputmsb_r1, outputlsb_r1, ...
PM0014 arithmetic library functions 21/46 5.4 multiplication 5.4.1 mul_q15_q15_q31 mul_q15_q15_q31 (short leftop, short rightop, long *output) description: multiplication of two real 16-bit fractional operands. argument: leftop left operand. rightop right operand. output output pointer. algorithm: leftop * rightop = output note: none assembly source code: mul_q15_q15_q31.asm code size and cycles: size: 22 bytes instruction cycles: 10 test: two files are provided to test the function: an input vector file (mul_q15_q15_q31.in) and an output vector file (mul_q15_q15_q31.res): mul_q15_q15_q31.in is made as follows: leftop1, rightop1, ... mul_q15_q15_q31.res is made as follows: output1, ...
arithmetic library functions PM0014 22/46 5.4.2 mul_q31_q31_q31 mul_q31_q31_q31 (short leftopmsb, short leftoplsb, short rightopmsb, short rightoplsb, long *output) description: multiplication of two real 32-bit fractional operands. output is on 32 bits. argument: leftopmsb left operand most significant bits. leftoplsb left operand least significant bits. rightopmsb right operand most significant bits. rightoplsb right operand least significant bits. output output pointer. algorithm: leftop * rightop = output note: none assembly source code: mul_q31_q31_q31.asm code size and cycles: size: 54 bytes instruction cycles: 19 test: two files are provided to test the function: an input vector file (mul_q31_q31_q31.in) and an output vector file (mul_q31_q31_q31.res): mul_q31_q31_q31.in is made as follows: leftopmsb1, leftoplsb1, rightopmsb1, rightoplsb1, ... mul_q31_q31_q31.res is made as follows: output1,...
PM0014 arithmetic library functions 23/46 5.4.3 cmul_q15_q15_q15 cmul_q15_q15_q15 (short leftop_i, short leftop_r, short rightop_i, short rightop_r, short *output). description: multiplication of two complex 32-bit (16 bits for each part) inputs. output is on 32 bits (16 bits for each part). argument: leftop_i left operand imaginary part. leftop_r left operand real part. rightop_i right operand imaginary part. rightop_r right operand real part. output output pointer. algorithm: leftop_r * rightop_r - leftop_i * rightop_i = output_r leftop_r * rightop_i + leftop_r * rightop_i = output_i note: output imaginary part is contained in the highest address (pointed by output + 2). output real part is in the lowest address (pointed by output). assembly source code: cmul_q15_q15_q15.asm code size and cycles: size: 36 bytes instruction cycles: 14 test: two files are provided to test the function: an input vector file (cmul_q15_q15_q15.in) and an output vector file (cmul_q15_q15_q15.res): cmul_q15_q15_q15.in is made as follows: leftop_i1, leftop_r1, rightop_i1, rightop_r1, ... cmul_q15_q15_q15.res is made as follows: output_i1, output_r1, ...
arithmetic library functions PM0014 24/46 5.4.4 cmul_q31_q31_q31 cmul_q31_q31_q31 (short op1_i_msb, short op1_i_lsb, short op1_r_msb, short op1_r_lsb, short op2_i_msb, short op2_i_lsb, short op2_r_msb, short op2_r_lsb, long *output). description: multiplication of two complex 64-bit (32 bits for each part) inputs. output is on 64 bits (32 bits for each part). argument: op1_i_msb left operand imaginary part most significant bits. op1_i_lsb left operand real part least significant bits. op1_r_msb right operand imaginary part most significant bits. op1_r_lsb right operand real part least significant bits. op2_i_msb left operand imaginary part most significant bits. op2_i_lsb left operand real part least significant bits. op2_r_msb right operand imaginary part most significant bits. op2_r_lsb right operand real part least significant bits. output output pointer. algorithm: leftop_r * rightop_r - leftop_i * rightop_i = output_r leftop_r * rightop_i + leftop_r * rightop_i = output_i note: output imaginary part is contained in the highest address (pointed by output + 4). output real part is in the lowest address (pointed by output). assembly source code: cmul_q31_q31_q31.asm code size and cycles: size: 214 bytes instruction cycles: 75 test: two files are provided to test the function: an input vector file (cmul_q31_q31_q31.in) and an output vector file (cmul_q31_q31_q31.res): cmul_q31_q31_q31.in is made as follows: leftopmsb_i1, leftoplsb_i1, leftopmsb_r1, leftoplsb_r1, rightopmsb_i1, rightoplsb_i1, rightopmsb_r1, rightoplsb_r1, ... cmul_q31_q31_q31.res is made as follows: outputmsb_i1, outputlsb_i1, ...
PM0014 arithmetic library functions 25/46 5.5 division 5.5.1 div_q31_q15_q15 div_q31_q15_q15 (short leftopmsb, short leftoplsb, short rightop, short *output). description: division of two real fractional i nputs. dividend is on 32 bits, divisor on 16 bits and quotient on 16 bits. argument: leftopmsb left operand most significant bits. leftopls left operand least significant bits. rightop right operand. output output pointer. algorithm: leftop / rightop = output note: the dividend must be smaller than the divisor for a valid result. divisions on limits (for example, division of 1 by 1 or of -1 by -1) are not computed by this routine. the algorithm implemented does not allow integer division. for dividing two integers (dividend in 32.0 format and divisor in 16.0), shift the dividend one bit to the left (into 31.1 format) before dividing. assembly source code: div_q31_q15_q15.asm code size and cycles: size: 98 bytes instruction cycles: 216 test: two files are provided to test the function: an input vector file (div_q31_q15_q15.in) and an output vector file (div_q31_q15_q15.res): div_q31_q15_q15.in is made as follows: leftopmsb1, leftoplsb1, rightop1 ... div_q31_q15_q15.res is made as follows: output1, ...
arithmetic library functions PM0014 26/46 5.5.2 div_q63_q31_q31 div_q63_q31_q31 (short leftopmsb, short leftop2b, short leftop3b, short leftoplsb,short rightopmsb, short rightoplsb, long *output) description: division of two real fractional i nputs. dividend is on 64 bits, divisor on 32 bits and quotient on 32 bits. argument: leftopmsb left operand most significant bits high. leftop2b left operand most significant bits low. leftop3b left operand least significant bits high. leftoplsb left operand least significant bits low. rightopmsb right operand most significant bits. rightoplsb right operand least significant bits. output output pointer. algorithm: leftop / rightop = output note: the dividend must be smaller than the divisor for a valid result. divisions on limits (for example, division of 1 by 1 or of -1 by -1) are not made by this routine. the algorithm implemented does not allow integer division. for dividing two integers (dividend in 64.0 format and divisor in 32.0), shift the dividend one bit to the left (into 63.1 format) before dividing. assembly source code: div_q63_q31_q31.asm code size and cycles: size: 204 bytes instruction cycles: 892 test: two files are provided to test the function: an input vector file (div_q63_q31_q31.in) and an output vector file (div_q63_q31_q31.res): div_q63_q31_q31.in is made as follows: leftopmsb1, leftop2b1, leftop3b1, leftoplsb1, rightopmsb1, rightoplsb1 ... div_q63_q31_q31.res is made as follows: output1, ...
PM0014 arithmetic library functions 27/46 5.5.3 cdiv_q31_q15_q15 cdiv_q31_q15_q15 (short leftopimsb, short leftopilsb, short leftoprmsb, short leftoprlsb, short rightopi, short rightopr, short *output). description: division of two complex fractional in puts. dividend is on 64 bits (32 bits for each part), divisor and quotient on 32 bits (16 bits for each part). argument: leftopimsb left operand imaginary part most significant bits. leftopilsb left operand imaginary part least significant bits. leftoprmsb left operand real part most significant bits. leftoprlsb left operand real part least significant bits. rightopi right operand imaginary part. rightopr right operand real part. output output pointer. algorithm: note: output imaginary part is contained in the lowest address (pointed by output). output real part is in the highest address (pointed by output + 2). if c 2 + d 2 is equal to 0, there is a result saturation to the maximum positive value. c 2 + d 2 must be smaller than the dividend real part and than the dividend imaginary part for a valid result. else, there is a result saturation to the maximum positive or negative value. if c 2 + d 2 , ac + bd or bc - ad is greater than 1 or smaller than -1, it saturates to the maximum positive or negative value. if c 2 + d 2 and ac + bd or bc - ad are both a maximum value. the real part of the result is not valid (respectively the imaginary part of the result). the implemented algorithm does not allow integer division. for dividing integers (dividend in 32.0 format and divisor in 16.0), shift the dividend one bit to the left (into 31.1 format) before dividing. assembly source code: cdiv_q31_q15_q15.asm code size and cycles: size: 262 bytes instruction cycles: 470 aib + cid + -------------- ac bd + c 2 d 2 + ------------------- -i bc ad ? c 2 d 2 + ------------------- + =
arithmetic library functions PM0014 28/46 test: two files are provided to test the function: an input vector file (cdiv_q31_q15_q15.in) and an output vector file (cdiv_q31_q15_q15.res): cdiv_q31_q15_q15.in is made as follows: leftopmsb_i1, leftoplsb_i1, leftopmsb_r1, leftoplsb_r1, rightop_i1, rightop_r1, ... cdiv_q31_q15_q15.res is made as follows: output_r1, output_i1 ...
PM0014 arithmetic library functions 29/46 5.5.4 cdiv_q31 cdiv_q31 (short leftopimsb, short leftopilsb, short leftoprmsb, short leftoprlsb, short rightopimsb, short rightopilsb, short rightoprmsb, short rightoprlsb, long *output). description: division of two complex fractional inputs. dividend, divisor and quotient are on 64 bits (32 bits for each part). argument: leftopimsb left operand imaginary part most significant bits. leftopilsb left operand imaginary part least significant bits. leftoprmsb left operand real part most significant bits. leftoprlsb left operand real part least significant bits. rightopimsb right operand imaginary part most significant bits. rightopilsb right operand imaginary part least significant bits. rightoprmsb right operand real part most significant bits. rightoprlsb right operand real part least significant bits. output output pointer. algorithm: note: output imaginary part is contained in the lowest addresses (pointed by output). output real part is in the highest addresses (pointed by output + 4). if c 2 + d 2 is equal to 0, result saturates to the maximum positive value. c 2 + d 2 must be smaller than the dividend real part and than the dividend imaginary part for a valid result. else, there is a result saturation to the maximum positive or negative value. if c 2 + d 2 and ac + bd (respectively c 2 + d 2 and bc - ad) are both a maximum value. the result real pa rt is not valid (respectively the result imaginary part). the implemented algorithm doesn?t allow integer division. for dividing integers (dividend in 32.0 format and divisor in 16.0), shift the dividend one bit to the left (into 31.1 format) before dividing. assembly source code: cdiv_q31.asm code size and cycles: size: 442 bytes instruction cycles: 1148 aib + cid + -------------- ac bd + c 2 d 2 + ------------------- -i bc ad ? c 2 d 2 + ------------------- + =
arithmetic library functions PM0014 30/46 test: two files are provided to test the function: an input vector file (cdiv_q31.in) and an output vector file (cdiv_q31.res): cdiv_q31.in is made as follows: leftopimsb1, leftopilsb1, leftoprmsb1, leftoprlsb1, rightopimsb1, rightopilsb1, rightoprmsb1, rightoprlsb1, ... cdiv_q31.res is made as follows: output_r1, output_i1, ...
PM0014 arithmetic library functions 31/46 5.6 matrix multiply 5.6.1 mmul_q15_q15_q15 void mmul_q15_q15_q15 (short mat1[][], int row1, int column1, short mat2[][], int column2, short output[][]). description: real 16-bit fractional matrix multiply. the result matrix is on 1.15 format. argument: mat1 pointer to matrix 1. row1 number of rows in matrix 1. column1 number of co lumns in matrix 1. mat2 pointer to matrix 2. column2 number of co lumns in matrix 2. output pointer to result matrix algorithm: output (i, j) = mat1(1, k) x mat2(k, j) note: matrix 1 and matrix 2 should be stored in the dpram. the output matrix saturates to 1 or -1 if the result is greater than 1 or respectively lower than -1. assembly source code: mmul_q15_q15_q15.asm code size and cycles: size: 122 bytes instruction cycles: 40 + row1 * (6 + column2 * (8 + column1)) test: to test this function, two test cases are provided. each test case has two input vector files that contain the matrix to multiply and one output vector file that contains the output matrix. for instance, mat1_4_3.in and mat2_3_2.in contains respectively a matrix[4][3] and a matrix [3][2]. be aware that it is possible to multiply a matrix[4][3] by a matrix [3][2] and not the inverse. an input file as well as the output file contains the elements of the matrix sorted as follows: op_row1_col1, op_row1_col2, op_row1_col3... ...op_row2_col1,op_row2_col2... k0 = column1 ?
arithmetic library functions PM0014 32/46 5.6.2 mvm_q15_q15_q15 void mvm_q15_q15_q15 (short mat[][], short *vectin, int n, short *output). description: real 16-bit fractional [n*n] [n*1] matrix multiply. the result vector is on 1.15 format. argument: mat pointer to matrix. vectin pointer to input vector. n size of the squared matrix and size of vectors. output pointer to result vector. algorithm: output (i) = mat(i, k) x vectin(k) note: matrix and vector should be stored in the dpram. the output vector saturates to 1 or -1 if the result is greater than 1 or respectively lower than -1. assembly source code: mvm_q15_q15_q15.asm code size and cycles: size: 60 bytes instruction cycles: n 2 + 10n - 10 test: to test this function, two test cases are provided. each test case has two input vector files that contain the matrix to multiply and one output vector file that contains the output matrix. for instance, mat_10_10.in and vect_10_1.in contains respectively a matrix[10][10] and a vector [10][1]. the input file as well as the output file contains the elements of the matrix sorted as follows: op_row1_col1, op_row1_col2, op_row1_col3... ....op_row2_col1,op_row2_col2... k0 = n ?
PM0014 arithmetic library functions 33/46 5.7 function approximation 5.7.1 sqrt_p16q16_p8q8 void sqrt_p16q16_p8q8 (short xmsb, short xlsb, short *output). description: the square root function is approximated by the hoerner polynomial. the input is in 16.16 format and the output is in 8.8 format with a precision to within three least significant bits. argument: xmsb input most significant bits. xlsb input least significant bits. output output pointer. algorithm: x 1/2 0.2075806 + 1.454895 x - 1.34491 x 2 +1.106812 x 3 - 0.536499 x 4 + 0.11212116 x 5 note: the input value can range from 0 to 2 15 - 1/2 15 . in fact the previous approximation is valid only between 0.5 and 1 but all inputs are scaled into this range. assembly source code: sqrt_p16q16_p8q8.asm code size and cycles: size: 330 bytes instruction cycles: 164 test: two files are provided to test the function: an input vector file (sqrt_p16q16_p8q8.in) and an output vector file (sqrt_p16q16_p8q8.res): sqrt_p16q16_p8q8.in is made as follows: oplsb1, opmsb1, oplsb2, opmsb2, ... sqrt_p16q16_p8q8.res is made as follows: output1, output2, ...
signal processing library functions PM0014 34/46 6 signal processing library functions 6.1 overview in this part, a set of signal processing functions for c programmers on st10 are presented. 6.2 data type libst10.h (c compiler package) defines the data types used for st10 programming. the following types are used in the library: filter: structure containing all the elements needed for filtering. filt.numbercoeffs : number of filter coefficients. filt.numberoutputsamples : number of output samples. filt.coeffptr : pointer on filter coefficients. filt.inputptr : pointer on input samples. filt.outputptr : pointer on output samples. filt.delaylineptr : pointer on delay line. library?s users have to fill the different fiel ds of this structure before calling any filtering function. according to the filter type, the number of coefficients definition changes. examples: .fir: y(n)=a0*x(n)+a1*x(n-1)+...+a15*x(n-15) store numbercoeffs=16 .iir direct form y(n)=b0*x(n)+b1*x(n-1)+...+b15*x(n-15)+a1*y(n-1)+...+a15*y(n-15) store numbercoeffs=32 (a0=0 is stored in memory) .iir cascaded biquad form y(n)=b00*x(n)+...+a02*y(n-2)+.....+a92*y(n-2) be careful: store numbercoeffs = numbercells = 10 ! the delay line is a buffer in memory used by filtering functions to store previous samples needed to perform calculation of the next output sample. the delay line size depends on the number of coefficients.
PM0014 signal processing library functions 35/46 6.3 finite impulse response filters 6.3.1 fir_q15_q15_q15 fir_q15_q15_q15 (struct filter *firptr). description: real fir filter of 16-bit fractional inputs, coefficients and outputs. argument: firptr filter pointer. algorithm: y(n) = b i * x (n - i) note: the delay line must be stored in dpram. its size is 2*nb_coeff. before the first call to the function, the delay line must be initialized to 0. there is a saturation to 1 (respectively -1) if the computed output sample is greater than 1 (respectively lower than -1). example of the use for fir_q15_q15_q15: # define firnumbercoeffs numberofcoefficients #define nboutput numberofoutputsamples iram short delayline [firnumbercoeffs]; iram short coeff [firnumbercoeffs]; void main () { // data definition short input[nboutput]; short out[nboutput]; // here should be the coef[] and input[] initialization. see the test part... // declare a filter structure struct filter *filt; // initialisation of filt filt.numbercoeffs = firnumbercoeffs; filt.numberoutputsamples = nboutput; filt.coeffptr = coeff; filt.inputptr = input; filt.outputptr = out; filt.delaylineptr = delayline; //filter processing fir_q15_q15_q15(&filt); } coefficients must be stored in memory as follow: addr filt.coeffptr ----> a 0 addr filt.coeffptr + 2 ----> a 1 ... addr filt.coeffptr + 2 * (firnumbercoeffs -1)----> a firnumbercoeffs-1 assembly source code: fir_q15_q15_q15.asm i0 = nbcoeff 1 ? ?
signal processing library functions PM0014 36/46 code size and cycles: size: 88 bytes instruction cycles: 30 + nboutput * (12 + firnumbercoeffs) test: two test cases are provided. for each case, two files allow to test the function: an input vector file (filterx_q15_q15_q15.in) an output vector file (filterx_q15_q15_q15.res). the configuration is the following: number of coefficients: 64 number of output samples: 201 to perform the test, initialize the delay line[] to zero, then coeff[] and input[] with the filterx_q15_q15_q15.in file. the first values are the coefficients of the filter and the rest of the values are the input values. (see the example for declarations).
PM0014 signal processing library functions 37/46 6.3.2 fir_q15_q31_q15 fir_q15_q31_q15 (struct filter *firptr). description: real fir filter of 16-bit fractional inputs and outputs. fractional coefficients are on 32 bits. argument: firptr filter pointer. algorithm: y(n) = b i * x (n - i) note: the delay line must be stored in dpram. its size is 2*2*nb_coeff. before the first call to the function, the delay line must be initialized to 0. there is a saturation to 1 (respectively -1) if the computed output sample is greater than 1 (respectively lower than -1). example of the use for fir_q15_q31_q15: #define firnumbercoeffs numberofcoefficients #define nboutput numberofoutputsamples iram short delayline[firnumbercoeffs]; iram short coeff[2*firnumbercoeffs];//coef are 32-bit wide void main () { // data definition short input[nboutput]; short out[nboutput]; // here should be the coef[] and input[] initialization. see the test part... // declare a filter structure struct filter *filt; // initialisation of filt filt.numbercoeffs = firnumbercoeffs; filt.numberoutputsamples = nboutput; filt.coeffptr = coeff; filt.inputptr = input; filt.outputptr = out; filt.delaylineptr = delayline; //filter processing fir_q15_q31_q15(&filt); } coefficients must be stored in memory as follow: addr filt.coeffptr ----> a 0 lsb addr filt.coeffptr + 2 ----> a 0 msb ... addr filt.coeffptr + 4 *(firnumbercoeffs -2)----> a firnumbercoeffs-1 msb assembly source code: fir_q15_q31_q15.asm code size and cycles: size: 130 bytes instruction cycles: 34 + nboutput * (16 + 2 * firnumbercoeffs) i0 = nbcoeff 1 ? ?
signal processing library functions PM0014 38/46 test: two test cases are provided. for each test case, two files allow to test the function: an input vector file (filterx_q15_q31_q15.in) an output vector file (filterx_q15_q31_q15.res). the configuration is the following: number of coefficients: 32 number of output samples: 201 to perform the test, initialize the delay line[] to zero, then coeff[] and input[] with the filterx_q15_q31_q15.in file. the first values are the coefficients (lsb first) of the filter and the rest of the values are the input values. (see the example for declarations).
PM0014 signal processing library functions 39/46 6.3.3 fir_q31_q31_q31 fir_q31_q31_q31(struct filter *firptr). description: real fir filter of 32-bit fractional inputs, coefficients and outputs. argument: firptr filter pointer. algorithm: y(n) = b i * x (n - i) note: the delay line must be stored in dpram. its size is 2*2*nb_coeff. before the first call to the function, the delay line must be initialized to 0. there is a saturation to 1 (respectively -1) if the computed output sample is greater than 1 (respectively lower than -1). example of the use for fir_q31_q31_q31: #define firnumbercoeffs numberofcoefficients #define nboutput numberofoutputsamples iram short delayline[firnumbercoeffs]; iram short coeff[2*firnumbercoeffs];//coef are 32-bit wide void main () { // data definition short input[2*nboutput];//input are 32-bit wide short out[2* nboutput];//output are 32-bit wide // here should be the coef[] and input[] initialization. see the test part... // declare a filter structure struct filter *filt; // initialisation of filt filt.numbercoeffs = firnumbercoeffs; filt.numberoutputsamples = nboutput; filt.coeffptr = coeff; filt.inputptr = input; filt.outputptr = out; filt.delaylineptr = delayline; //filter processing fir_q31_q31_q31(&filt); } coefficients must be stored in memory as follows: addr filt.coeffptr ----> a 0 lsb addr filt.coeffptr + 2 ----> a 0 msb ... addr filt.coeffptr + 4 *(firnumbercoeffs -2)----> a firnumbercoeffs-1 msb inputs and outputs are stored in memory as follows: addr filt.inputptr ----> x 0 lsb addr filt.inputptr + 2 ----> x 0 msb ... addr filt.input + 4 *(nboutput -2)----> a nboutput-1 msb addr filt.outputptr ----> y 0 lsb addr filt.outputptr + 2 ----> y 0 msb ... addr filt.outputptr + 4 *(nboutput -2)----> a nboutput-1 msb i0 = nbcoeff 1 ? ?
signal processing library functions PM0014 40/46 assembly source code: fir_q31_q31_q31.asm code size and cycles: size: 194 bytes instruction cycles: 34 + nboutput * (20 + 4 * firnumbercoeffs) test: two test cases are provided. for each test case, two files allow to test the function: an input vector file (filterx_q31_q31_q31.in) an output vector file (filterx_q31_q31_q31.res). the configuration is the following: number of coefficients: 32 number of output samples: 201 to perform the test, initialize the delay line[] to zero, then coeff[] and input[] with the filterx_q31_q31_q31.in file./ the first values are the coefficients (lsb first) of the filter and the rest of the values are the input values (lsb first). the output vector file contains the result value (lsb first). (see the example for declarations).
PM0014 signal processing library functions 41/46 6.4 infinite impulse response filter 6.4.1 iir2_q15_q15_q15 iir2_q15_q15_q15 (struct filter *iirptr). description: real iir filter of 16-bit fractional inputs, coefficients and outputs. the filter implemented is a direct form ii. argument: iirptr filter pointer. algorithm: w(n) = x(n) + a(k) * w(n - k) notes: the w(i) are the filter internal states and are saved in the delay line during computation. the delay line must be stored in dpram. before the first call to the function, the delay line must be initialized to 0. the length of the delay line must be equal to the number of b(i) coefficients. as the number of b(i) coefficients is supposed to be equal to the number of a(i) coefficients, the length of the delay line is equal to iirnumbercoeffs/2. library users must care about the a(i) coefficients. if their modulus are too great, the filter internal states w(i) can saturate. the output samples are in this condition false. the coefficient a 0 must be initialized to 0. there is a saturation to 1 (respectively -1) if the computed output sample is greater than 1 (respectively lower than -1). example of the use for iir2_q15_q15_q15: #define iirnumbercoeffs numberofcoefficients #define nboutput numberofoutput iram short delayline[iirnumbercoeffs/2]; iram short coeff[iirnumbercoeffs]; void main() { // data definition short input[nboutput]; short out[nboutput]; // here should be the coef[] and input[] initialization. see the test part... // declare a filter structure struct filter filt; //filter initialisation filt.numbercoeffs = iirnumbercoeffs; filt.numberoutputsamples = nboutput; filt.coeffptr = coeff; filt.inputptr = input; filt.outputptr = out; filt.delaylineptr = delayline; //filter processing iir2_q15_q15_q15(&filt); } k1 = iirnumbercoeff 2 ---------------------------------------------- 1 ? ?
signal processing library functions PM0014 42/46 coefficients must be stored in memory as follow: addr iir.coeffptr ----> b 0 addr iir.coeffptr + 2 ----> b 1 ... addr iir.coeffptr + 2 * (iirnumbercoeffs/2 - 1)----> b (iirnumbercoeff/2)-1 addr iir.coeffptr + 2 * (iirnumbercoeffs/2)----> a 0 = 0 addr iir.coeffptr + 2 * (iirnumbercoeffs/2 + 1) ----> a 1 ... addr iir.coeffptr + 2 * (iirnumbercoeffs - 1)----> a (iirnumbercoeff/2)-1 assembly source code: iir2_q15_q15_q15.asm code size and cycles: size: 130 bytes instruction cycles: 36 + nboutput * (17 + iirnumbercoeffs) test: two test cases are provided. for each test case, two files allow to test the function: an input vector file (dirfilterx_q15_q15_q15.in) and an output vector file (dirfilterx_q15_q15_q15.res). the configuration is the following: number of coefficients: 32 number of output samples: 201 to perform the test, initialize the delay line[] to zero, then coeff[] and input[] with the dirfilterx_q15_q15_q15.in file: the first values are the coefficients of the filter and the rest of the values are the input values. (see the example for declarations).
PM0014 signal processing library functions 43/46 6.4.2 iirbiquad5_q15_q15_q15 iirbiquad5_q15_q15_q15 (struct filter *iirptr). description: real iir filter of 16-bit fractional inputs, coefficients and outputs. the filter implemented is an iir cascaded biquad cells form. argument: iirptr filter pointer. algorithm: with q = filter order/2, the number of cells notes: the filter order must be an even number. each biquad cells is implemented in the direct form ii. the delay line must be stored in dp ram. its size is 2*3*q. before the first call to the function, the delay line must be initialized to 0. the coefficient a 0 is fixed to 1. library users must care about the a(i) coefficients. if they are too big in modulus, the filter internal states w(i) can saturate. the output samples are in this condit ion false. this problem is less important in iirbiquad5_q15_q15_q15 than in iir2_q15_q15_q15 because there are less a(i) coefficients used to compute biquad cells. there can be some error bits because of the internal rounding. there is a saturation to 1 (respectively -1) if the computed output sample is greater than 1 (respectively lower than -1). example of the use for iirbiquad5_q15_q15_q15: #define iirnumbercells numberofcells #define nboutput numberofoutput iram short delayline[iirnumbercells*3]; iram short coeff[iirnumbercells*5]; void main() { // data definition short input[nboutput]; short out[nboutput]; // here should be the coef[] and input[] initialization. see the test part... // declare a filter structure struct filter filt; //filter initialisation filt.numbercoeffs = iirnumbercoeffs; filt.numberoutputsamples = nboutput; filt.coeffptr = coeff; filt.inputptr = input; filt.outputptr = out; filt.delaylineptr = delayline; //filter processing iirbiquad5_q15_q15_q15(&filt); } hz () k0 = q1 ? = b 0k + b 1k x z -1 + b 2k x z -2 1 - a 1k x z -1 - a 2k x z -2
signal processing library functions PM0014 44/46 coefficients must be stored in memory as follow: addr iir.coeffptr ----> b 00 addr iir.coeffptr + 2 ----> b 10 addr iir.coeffptr + 4----> b 20 addr iir.coeffptr +6----> a 10 addr iir.coeffptr + 8 ----> a 20 ... addr iir.coeffptr + 2 * 5 * (q - 1)----> b 0(q-1) addr iir.coeffptr + 2 * 5 *(q-1) + 2----> b 1(q-1) addr iir.coeffptr + 2 * 5 * (q - 1) + 4 ----> b 2(q-1) addr iir.coeffptr + 2 * 5 * (q - 1) + 6 ----> a 1(q-1) addr iir.coeffptr + 2 * 5 *(q-1) + 8----> a 2(q-1) assembly source code: iirbiquad5_q15_q15_q15.asm code size and cycles: size: 136 bytes instruction cycles: 34 + nboutput * (12 + 15 * iirnumbercells) test: two test cases are provided. for each test case, two files allow to test the function: an input vector file (biqfilterx_q15_q15_q15.in) and an output vector file (biqfilterx_q15_q15_q15.res). the configuration is the following: number of cells: 3 number of output samples: 201 to perform the test, initialize the delay line[] to zero, then coeff[] and input[] with the biqfilterx_q15_q15_q15.in file. the first values are the coefficients of the filter and the rest of the values are the input values. (see the example for declarations).
PM0014 revision history 45/46 7 revision history the st10-dsp library may be periodically updated, incorporating new functions and fixes as they are available. read the readme.txt available in the root directory of every release. table 3. document revision history date revision changes 28-may-2002 1 initial release. 04-mar-2008 2 document reformatted. reference to st10f280 removed. end-user license agreement section removed. 18-sep-2013 3 updated disclaimer
PM0014 46/46 please read carefully: information in this document is provided solely in connection with st products. stmicroelectronics nv and its subsidiaries (?st ?) reserve the right to make changes, corrections, modifications or improvements, to this document, and the products and services described he rein at any time, without notice. all st products are sold pursuant to st?s terms and conditions of sale. purchasers are solely responsible for the choice, selection and use of the st products and services described herein, and st as sumes no liability whatsoever relating to the choice, selection or use of the st products and services described herein. no license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. i f any part of this document refers to any third party products or services it shall not be deemed a license grant by st for the use of such third party products or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoev er of such third party products or services or any intellectual property contained therein. unless otherwise set forth in st?s terms and conditions of sale st disclaims any express or implied warranty with respect to the use and/or sale of st products including without limitation implied warranties of merchantability, fitness for a particul ar purpose (and their equivalents under the laws of any jurisdiction), or infringement of any patent, copyright or other intellectual property right. st products are not designed or authorized for use in: (a) safety critical applications such as life supporting, active implanted devices or systems with product functional safety requirements; (b) aeronautic applications; (c) automotive applications or environments, and/or (d) aerospace applications or environments. where st products are not designed for such use, the purchaser shall use products at purchaser?s sole risk, even if st has been informed in writing of such usage, unless a product is expressly designated by st as being intended for ? automotive, automotive safe ty or medical? industry domains according to st product design specifications. products formally escc, qml or jan qualified are deemed suitable for use in aerospace by the corresponding governmental agency. resale of st products with provisions different from the statements and/or technical features set forth in this document shall immediately void any warranty granted by st for the st product or service described herein and shall not create or extend in any manner whatsoev er, any liability of st. st and the st logo are trademarks or registered trademarks of st in various countries. information in this document supersedes and replaces all information previously supplied. the st logo is a registered trademark of stmicroelectronics. all other names are the property of their respective owners. ? 2013 stmicroelectronics - all rights reserved stmicroelectronics group of companies australia - belgium - brazil - canada - china - czech republic - finland - france - germany - hong kong - india - israel - ital y - japan - malaysia - malta - morocco - philippines - singapore - spain - sweden - switzerland - united kingdom - united states of america www.st.com


▲Up To Search▲   

 
Price & Availability of PM0014

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X